package com.kingsalert.kingsalert.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kingsalert.kingsalert.R;

public class NumberTextView_S extends RelativeLayout {

    private Context mContext;

    private CharSequence text;

    private LinearLayout groupLayout;

    public NumberTextView_S(Context context) {
        super(context);
        initView(context,null);
    }

    public NumberTextView_S(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context, attrs);
    }

    public NumberTextView_S(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context, attrs);
    }

    private void initView(Context context,AttributeSet attrs){

        mContext = context;

        if (attrs!=null){
            @SuppressLint("Recycle") TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NumberTextView);
            text = typedArray.getText(R.styleable.NumberTextView_android_text);
        }

        View view = View.inflate(context,R.layout.view_number_text,this);
        groupLayout = view.findViewById(R.id.tvn_layout_group);

        if (text == null) text = "";

        setText(text);

    }

    public void setText(CharSequence text){
        this.text = text;
        groupLayout.removeAllViews();

        for (int i = 0; i<text.length(); i++){
            char c = text.charAt(i);
            addChar(c);
        }
    }

    private void addChar(char c){
        View view = View.inflate(mContext,R.layout.view_bg_number_s,null);
        TextView charTv = view.findViewById(R.id.vbn_tv_char);
        charTv.setText(String.valueOf(c));
        groupLayout.addView(view);
    }


}
